package com.ghh.dao;

import com.alibaba.dubbo.config.annotation.Service;
import com.ghh.pojo.Permission;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface PermissionDao {
    //根据角色ID查询关联的权限
    @Select("select t_permission.* from t_permission,t_role_permission where t_permission.id=t_role_permission.permission_id and t_role_permission.role_id=#{id}")
    Set<Permission> findByRoleId(Integer id);

    //分页查询
    @Select("<script>select * from t_permission <if test=\"value!=null and value!=''\">where name=#{value}</if></script>")
    Page<Permission> findByCondition(@Param("value") String queryString);

    //根据ID查询权限
    @Select("select * from t_permission where id = #{id}")
    Permission findById(Integer id);

    //修改
    @Update(" update t_permission set name = #{name},keyword = #{keyword},description = #{description} where id = #{id}")
    void edit(Permission permission);

    //查询有无该权限
    @Select("select count(*) from t_role_permission where permission_id = #{permission_id}")
    long findCountByPermissionId(Integer id);

    //删除权限
    @Delete("delete from t_permission where id = #{id};")
    void deleteById(Integer id);

    //添加
    @Insert("insert into t_permission value (#{name},#{keyword},#{description})")
    void addPermission(Permission permission);

    //查询所有权限
    @Select("select * from t_permission")
    List<Permission> findAll();
}
